import network from '../../utils/network.js';
Page({
  data: {
    userInfo:[],
    isHiddenToast: true,
    page: 1,
    rows: 10,
    total:0,
    hasMoreData: true,
    list: [], 
    //当前选中导航的Inx值
    Inx: 0
  },
  // 新的绑定导航切换样式方法
  changeTab: function (event) {
    this.setData({
      Inx: event.currentTarget.dataset.index
    })
  },
  isShowToast: function () {
    this.setData({
      isHiddenToast: false
    })
  },
 
   
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    var that = this;
    wx.getStorage({//获取本地缓存
      key: "user",
      success: function (res) {
        that.setData({
          userInfo: res.data,
        });
        that.getManager_list('正在加载数据...')
      }
    });  
  },
  onDetail:function(e){
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/view/join_data/join_data?id='+id,   
    });
  },
  onGetSaleList:function(e){
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/view/join_team/join_team?id=' + id,
    });
  },
  onDelete:function(e){
    var that = this;
    const id = e.currentTarget.dataset.id
    var data = {
      id: id,
    }; 
    const message = "正在删除中";
    network.requestLoading('http://jbc.com/System/User/manager_delete', data, message, function (res) {
      if(res.code>0){
        wx.showToast({
          title: '删除成功',
        });
        that.data.page = 1;
        that.data.list = [];
        that.getManager_list('正在刷新数据')
      }else{
        wx.showToast({
          title: res.msg,
        });
      }
    }, function (res) {
      wx.showToast({
        title: '加载数据失败',
      })

    })
  },
 
  getManager_list: function (message) {
    var that = this;
    const shop_id = that.data.userInfo.shop_id; 
    var datas = that.data;
    var data = {
      shop_id: shop_id,
      ischeck: 1,
      page: datas.page,
      rows:datas.rows
    }; 
    network.requestLoading('http://jbc.com/System/User/manager_list', data, message, function (res) {
      var contentlistTem = that.data.list;
      if(res.code >0){
        if (contentlistTem.length < res.data.total){
          that.setData({
            page:datas.page+1,
            list: res.data.list,
          });  
        }else{
          that.setData({
            hasMoreData:false
          });
        }  

      }else{
        wx.showToast({
          title: res.msg,
        })
      }
    }, function (res) {
      wx.showToast({
        title: '加载数据失败',
      })

    })
  },
  /**
 * 页面相关事件处理函数--监听用户下拉动作
 */
  onPullDownRefresh: function () {
    this.data.page = 1;
    this.getManager_list('正在刷新数据')
    console.log("下拉加载更多")
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log("下滑加载更多")
    if (this.data.hasMoreData) {
      this.getManager_list('加载更多数据');
    } else {
      console.log("没有更多的数据")
      wx.showToast({
        title: '没有更多数据',
      })
    }
  },
})